package com.hison.tandainbao.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hison.tandainbao.entiy.pojo.domain.TbBlog;
import com.hison.tandainbao.entiy.pojo.dto.UserDTO;
import com.hison.tandainbao.response.ResponseResult;
import com.hison.tandainbao.service.TbBlogService;
import com.hison.tandainbao.util.UserHolder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: BlogController
 * @Descripiton: 博客控制类
 * @Author: 小郑
 * @Date： 2024/3/21 20:51
 * @Version：1.8
 **/
@RestController
@RequestMapping("/blog")
@Api(value = "博客信息管理接口", tags = "博客信息管理接口")
public class BlogController {

    @Autowired
    private TbBlogService tbBlogService;


    /**
     * 发布博客接口
     *
     * @param blog 博客
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/21
     * @see TbBlog
     * @see ResponseResult
     * @since version
     */
    @PostMapping("/publish")
    @ApiOperation(value = "发布博客", produces = "application/json", httpMethod = "POST")
    public ResponseResult  publishBlog(@RequestBody TbBlog blog){
        return tbBlogService.publishBlog(blog);
    }

    //普通用户浏览全部已经审核通过的博客
    @GetMapping("/getAllBlog")
    @ApiOperation(value = "获取所有已经审核通过的博客",produces = "application/json",httpMethod = "GET")
    public ResponseResult getAllBlog(@RequestParam(value = "current", defaultValue = "1") Integer current){
        return  tbBlogService.getAllBlog(current);
    }

    /**
     * 博客点赞
     * @param id
     * @return {@link ResponseResult}
     */
    @PutMapping("/like/{id}")
    @ApiOperation(value = "点赞博客",produces = "application/json", httpMethod = "PUT")
    public ResponseResult likeBlog(@PathVariable("id") Long id) {
        return tbBlogService.likeBlog(id);
    }

    /**
     * 查询我发布的博客
     * @param current
     * @return {@link ResponseResult}
     */
    @GetMapping("/of/me")
    @ApiOperation(value = "查询我发布的博客",produces ="application/json",httpMethod = "GET")
    public ResponseResult queryMyBlog(@RequestParam(value = "current", defaultValue = "1") Integer current) {
        return tbBlogService.queryMyBlog(current);
    }

    /**
     * 按 ID 查询博客
     *
     * @param id 同上
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/31
     * @see Long
     * @see ResponseResult
     * @since version
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取博客",produces = "application/json",httpMethod = "GET")
    public ResponseResult queryBlogById(@PathVariable("id") Long id) {
        return tbBlogService.queryBlogById(id);
    }

    /**
     * 查询当前博客点赞的用户列表
     * @param id
     * @return {@link ResponseResult}
     */
    @GetMapping("/likes/{id}")
    @ApiOperation(value = "查询当前博客的点赞用户列表",produces = "application/json",httpMethod = "GET")
    public ResponseResult queryBlogLikes(@PathVariable("id") Long id) {
        return tbBlogService.querBlogLikes(id);
    }


    /**
     * 查询关注的用户发布的博客
     *
     * @param max    麦克斯
     * @param offset 抵消
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/31
     * @see Long
     * @see Integer
     * @see ResponseResult
     * @since version
     */
    @GetMapping("/of/follow")
    @ApiOperation(value = "查询关注的用户发布的博客",produces = "application/json",httpMethod = "GET")
    public ResponseResult queryBlogFollow(@RequestParam(value = "lastId") Long max, @RequestParam(value = "offset",defaultValue = "0") Integer offset) {
        //查询博客
        return tbBlogService.queryBlogFollow(max,offset);
    }

    /**
     * 删除博客
     *
     * @param id 同上
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/31
     * @see Integer
     * @see ResponseResult
     * @since version
     *///删除博客
    @DeleteMapping("del/{bolgId}")
    @ApiOperation(value = "根据ID删除博客",produces = "application/json",httpMethod = "DELETE")
    public ResponseResult deleteBlog(@PathVariable("bolgId") String id) {
        return  tbBlogService.deleteBlog(id);
    }

    /**
     * 按名称获取博客
     *
     * @param name 名字
     * @return @return {@code ResponseResult }
     * @author $USER$
     * @date 2024/03/31
     * @see String
     * @see ResponseResult
     * @since version
     *///根据博客名称查找博客
    @GetMapping("/getBlogByName")
    @ApiOperation(value = "根据博客名称模糊查询博客",produces = "application/json",httpMethod = "GET")
    public  ResponseResult  getBlogByName(@RequestParam("name") String name){
        return  tbBlogService.getBlogByName(name);
    }
    //查看自己点赞的博客
    @GetMapping("/getMyLike")
    @ApiOperation(value = "获取自己点赞的博客",produces = "application/json",httpMethod = "GET")
    public  ResponseResult getMyLike(){
        return  tbBlogService.getMyLike();
    }


    //------------------------- 管理员---------------------------------------
    //审核博客
    @PutMapping("/updateStatusByAdmin")
    @ApiOperation(value = "管理员审核博客",produces ="application/json",httpMethod = "POST")
    public  ResponseResult updateStatusByAdmin(@RequestParam("blogId") String blogId,@RequestParam("status") Integer status){
        return  tbBlogService.updateStatusByAdmin(blogId,status);
    }



    //删除博客
    @DeleteMapping("delByAdmin/{bolgId}")
    @ApiOperation(value = "管理员根据ID删除博客",produces = "application/json",httpMethod = "DELETE")
    public ResponseResult deleByAdmin(@PathVariable("bolgId") String id) {
        return  tbBlogService.deleteBlog(id);
    }


    //管理员获取全部的信息
    //普通用户浏览全部已经审核通过的博客
    @GetMapping("/getAllBlogByAdmin")
    @ApiOperation(value = "管理员获取所有已经审核通过的博客",produces = "application/json",httpMethod = "GET")
    public ResponseResult getAllBlogByAdmin(@RequestParam(value = "current", defaultValue = "1") Integer current, @RequestParam(value = "total",defaultValue = "10") Integer total){
        return  tbBlogService.getAllBlogByAdmin(current,total);
    }

}